<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="ja" xml:lang="ja">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta http-equiv="Content-Script-Type" content="text/javascript" />
		<meta http-equiv="Content-Style-Type" content="text/css" />
		<title>コントロールパネル</title>

		<link rel="stylesheet" href="./assets/styles/default.css" type="text/css" />
		<link rel="stylesheet" type="text/css" href="./assets/styles/tablesorter.css" />
		<link type="text/css" href="./assets/styles/ui-lightness/jquery-ui-1.7.2.custom.css" rel="stylesheet" />

		<script src="assets/scripts/jquery-1.3.2.min.js" type="text/javascript"></script>
		<script src="assets/scripts/menu.js" type="text/javascript"></script>
		<script type="text/javascript" src="./assets/scripts/ui/ui.datepicker.js"></script>
		<script type="text/javascript">
		$(function() {
			$('#text_follow-date1').datepicker({
				changeMonth: true,
				changeYear: true,
				dateFormat: 'yy/mm/dd'
			});
			$('#text_follow-date2').datepicker({
				changeMonth: true,
				changeYear: true,
				dateFormat: 'yy/mm/dd'
			});
		});
		</script>


		<script type="text/javascript">
		$(function() {

			var costs = {};
{{ foreach from=$costs key=k item=v }}costs[{{ $k }}]={{ $v }};{{ /foreach }}
			var units = {};
{{ foreach from=$units key=k item=v }}units[{{ $k }}]='{{ $v }}';{{ /foreach }}

			// メッセージのフェード
			$('.message').fadeIn("slow");

			// 登録ボタン
			$('#btn_regist').click(function(){
				if( confirm('{{ if $forms.id =='' }}登録{{ else }}更新{{ /if }}してよろしいですか？') ){
					document.fm.submit();
				}
			});

			// 削除ボタン
			$('#btn_delete').click(function(){
				if( confirm('削除してよろしいですか？') ){
					document.fm.mode.value = 'delete';
					document.fm.submit();
				}
			});

			// 製品変更
			$('.amount').append('<span>');
			$('.prodName select').change(function(){
				var cost = costs[$(this).val()];
				var unit = units[$(this).val()];
				var amount = $(this).parent().parent().find('.calc').val();
				var target = $(this).parent().parent().find('.subTotal');
				var $unit = $(this).parent().parent().find('.amount').find('span');
				$unit.text(unit);
				if( !$(this).val() ) $unit.text('');

				if( $(this).val() != 0 && !isNaN(amount) && amount != ''){
					target.text(amount * cost);
				}else{
					target.text('');
				}
			});

			// 数量入力
			$('.calc').blur(function(){
				var target = $(this).parent().parent().find('.subTotal');
				var amount = $(this).val();
				var targetCost = $(this).parent().parent().find('.prodName select');
				var cost = targetCost.val();
				if(isNaN(amount)){
					alert('半角数字で入力してください');
					target.text('');
				}else if( cost != 0 ){
					target.text(amount * costs[cost]);
				}else{
					target.text('');
				}
				
			});

		});

{{ if $preview_id != '' }}
		// 印刷画面を開く
		function open_preview(){
			var url = './preview/shipping.php?id=' + {{ $preview_id }};
			window.open(url, 'printpreview');
		}
{{ /if }}
		</script>
	</head>
	<body id="">
{{ php }} include( MENU_FILE ); {{ /php }}
		<div id="header" class="clearfix"><div class="wrapper">
			<h1><a href="./">コントロールパネル</a></h1>
			<form id="form_logout" action="logout.php" method="post"><p>{{ $login.staff_name }} <input type="submit" id="button_logout" value="ログアウト" /></p></form>
		</div></div>

		<div id="container"><div class="wrapper">

			<h2>サンプル依頼</h2>

			<ul class="submenu clearfix">
				<li><a href="sample_index.php">サンプル依頼書一覧</a></li>
				<li><a href="sample_form.php">サンプル依頼書登録</a></li>
				<li><a href="ship_index.php">無償出荷一覧</a></li>
				<li><a href="ship_form.php">無償出荷登録</a></li>
				<li><a href="products_index.php">商品マスタ</a></li>
			</ul>


			<h3>無償出荷{{ if $forms.id =='' }}登録{{ else }}更新{{ /if }}</h3>

			<p class="message">{{ $message }}</p>
{{ if $phase == 'input' }}
			<form name="fm" action="ship_form.php" method="post">

				<table class="formTable">

					<tbody>
	{{ if $forms.id != '' }}
						<tr>
							<th>ID</th>
							<td>{{ $forms.disp_id }}</td>
							<th>登録日</th>
							<td>
								{{ $forms.r_date }}<input type="hidden" name="r_date" value="{{ $forms.r_date }}" />
							</td>
						</tr>
						<tr>
							<th>※依頼者名</th>
							<td>{{ $forms.request_name }}</td>
							<th>更新日</th>
							<td>
								{{ $forms.u_date }}<input type="hidden" name="u_date" value="{{ $forms.u_date }}" />
							</td>
						</tr>
	{{ else }}
						<tr>
							<th>※依頼者名</th>
							<td>
								<input type="text" name="request_name" id="text_short" class="text" value="{{ $forms.request_name }}" />
								{{ $err.request_name }}
							</td>
						</tr>
	{{ /if }}
					</tbody>
				</table>

{{ if $forms.id == '' }}
				<p class="note">※依頼書1件につき、「伝票区分」は1種類のみです。異なる「伝票区分」の無償出荷は、依頼書を分けてください。</p>

				<table id="inquiry_result" class="sortable">
					<thead>
						<tr>
							<th class="nosort"><h3>No.</h3></th>
							<th class="nosort"><h3>製品番号/品名</h3></th>
							<th class="nosort"><h3>伝票区分</h3></th>
							<th class="nosort"><h3>数量</h3></th>
							<th class="nosort"><h3>材料費</h3></th>
							<th class="nosort"><h3>目的/備考</h3></th>
						</tr>

					</thead>
					<tbody>
						<tr>
							<td>1</td>
							<td class="prodName">{{ html_options name=products[1] options=$products selected=$forms.products[1] }}</td>
							<td>{{ html_options name=denpyo[1] options=$arr_denpyo selected=$forms.denpyo[1] }}</td>
							<td class="amount"><input type="text" name="amount[1]" id="text_quater" class="text calc" value="{{ $forms.amount[1] }}" /></td>
							<td class="subTotal">{{ $subtotal[1] }}</td>
							<td><input type="text" name="biko[1]" id="text_half" class="text" value="{{ $forms.biko[1] }}" /></td>
						</tr>

						<tr>
							<td>2</td>
							<td class="prodName">{{ html_options name=products[2] options=$products selected=$forms.products[2] }}</td>
							<td>{{ html_options name=denpyo[2] options=$arr_denpyo selected=$forms.denpyo[2] }}</td>
							<td class="amount"><input type="text" name="amount[2]" id="text_quater" class="text calc" value="{{ $forms.amount[2] }}" /></td>
							<td class="subTotal">{{ $subtotal[2] }}</td>
							<td><input type="text" name="biko[2]" id="text_half" class="text" value="{{ $forms.biko[2] }}" /></td>
						</tr>

						<tr>
							<td>3</td>
							<td class="prodName">{{ html_options name=products[3] options=$products selected=$forms.products[3] }}</td>
							<td>{{ html_options name=denpyo[3] options=$arr_denpyo selected=$forms.denpyo[3] }}</td>
							<td class="amount"><input type="text" name="amount[3]" id="text_quater" class="text calc" value="{{ $forms.amount[3] }}" /></td>
							<td class="subTotal">{{ $subtotal[3] }}</td>
							<td><input type="text" name="biko[3]" id="text_half" class="text" value="{{ $forms.biko[3] }}" /></td>
						</tr>

						<tr>
							<td>4</td>
							<td class="prodName">{{ html_options name=products[4] options=$products selected=$forms.products[4] }}</td>
							<td>{{ html_options name=denpyo[4] options=$arr_denpyo selected=$forms.denpyo[4] }}</td>
							<td class="amount"><input type="text" name="amount[4]" id="text_quater" class="text calc" value="{{ $forms.amount[4] }}" /></td>
							<td class="subTotal">{{ $subtotal[4] }}</td>
							<td><input type="text" name="biko[4]" id="text_half" class="text" value="{{ $forms.biko[4] }}" /></td>
						</tr>

						<tr>
							<td>5</td>
							<td class="prodName">{{ html_options name=products[5] options=$products selected=$forms.products[5] }}</td>
							<td>{{ html_options name=denpyo[5] options=$arr_denpyo selected=$forms.denpyo[5] }}</td>
							<td class="amount"><input type="text" name="amount[5]" id="text_quater" class="text calc" value="{{ $forms.amount[5] }}" /></td>
							<td class="subTotal">{{ $subtotal[5] }}</td>
							<td><input type="text" name="biko[5]" id="text_half" class="text" value="{{ $forms.biko[5] }}" /></td>
						</tr>

						<tr>
							<td>6</td>
							<td class="prodName">{{ html_options name=products[6] options=$products selected=$forms.products[6] }}</td>
							<td>{{ html_options name=denpyo[6] options=$arr_denpyo selected=$forms.denpyo[6] }}</td>
							<td class="amount"><input type="text" name="amount[6]" id="text_quater" class="text calc" value="{{ $forms.amount[6] }}" /></td>
							<td class="subTotal">{{ $subtotal[6] }}</td>
							<td><input type="text" name="biko[6]" id="text_half" class="text" value="{{ $forms.biko[6] }}" /></td>
						</tr>

						<tr>
							<td>7</td>
							<td class="prodName">{{ html_options name=products[7] options=$products selected=$forms.products[7] }}</td>
							<td>{{ html_options name=denpyo[7] options=$arr_denpyo selected=$forms.denpyo[7] }}</td>
							<td class="amount"><input type="text" name="amount[7]" id="text_quater" class="text calc" value="{{ $forms.amount[7] }}" /></td>
							<td class="subTotal">{{ $subtotal[7] }}</td>
							<td><input type="text" name="biko[7]" id="text_half" class="text" value="{{ $forms.biko[7] }}" /></td>
						</tr>

						<tr>
							<td>8</td>
							<td class="prodName">{{ html_options name=products[8] options=$products selected=$forms.products[8] }}</td>
							<td>{{ html_options name=denpyo[8] options=$arr_denpyo selected=$forms.denpyo[8] }}</td>
							<td class="amount"><input type="text" name="amount[8]" id="text_quater" class="text calc" value="{{ $forms.amount[8] }}" /></td>
							<td class="subTotal">{{ $subtotal[8] }}</td>
							<td><input type="text" name="biko[8]" id="text_half" class="text" value="{{ $forms.biko[8] }}" /></td>
						</tr>

						<tr>
							<td>9</td>
							<td class="prodName">{{ html_options name=products[9] options=$products selected=$forms.products[9] }}</td>
							<td>{{ html_options name=denpyo[9] options=$arr_denpyo selected=$forms.denpyo[9] }}</td>
							<td class="amount"><input type="text" name="amount[9]" id="text_quater" class="text calc" value="{{ $forms.amount[9] }}" /></td>
							<td class="subTotal">{{ $subtotal[9] }}</td>
							<td><input type="text" name="biko[9]" id="text_half" class="text" value="{{ $forms.biko[9] }}" /></td>
						</tr>

						<tr>
							<td>10</td>
							<td class="prodName">{{ html_options name=products[10] options=$products selected=$forms.products[10] }}</td>
							<td>{{ html_options name=denpyo[10] options=$arr_denpyo selected=$forms.denpyo[10] }}</td>
							<td class="amount"><input type="text" name="amount[10]" id="text_quater" class="text calc" value="{{ $forms.amount[10] }}" /></td>
							<td class="subTotal">{{ $subtotal[10] }}</td>
							<td><input type="text" name="biko[10]" id="text_half" class="text" value="{{ $forms.biko[10] }}" /></td>
						</tr>
{{ else }}
				<table id="inquiry_result" class="sortable">
					<thead>
						<tr>
							<th class="nosort"><h3>No.</h3></th>
							<th class="nosort"><h3>製品番号/品名</h3></th>
							<th class="nosort"><h3>伝票区分</h3></th>
							<th class="nosort"><h3>数量</h3></th>
							<th class="nosort"><h3>単位</h3></th>
							<th class="nosort"><h3>材料費</h3></th>
							<th class="nosort"><h3>目的/備考</h3></th>
						</tr>

					</thead>
					<tbody>
						<tr>
							<td>1</td>
							<td class="prodName">{{ $products[$forms.products.1] }}</td>
							<td>{{ $arr_denpyo[$forms.denpyo.1] }}</td>
							<td>{{ $forms.amount[1] }}</td>
							<td>{{ $forms.unit[1] }}</td>
							<td class="subTotal">{{ $subtotal[1] }}</td>
							<td>{{ $forms.biko[1] }}</td>
						</tr>

						<tr>
							<td>2</td>
							<td class="prodName">{{ $products[$forms.products.2] }}</td>
							<td>{{ $arr_denpyo[$forms.denpyo.2] }}</td>
							<td>{{ $forms.amount[2] }}</td>
							<td>{{ $units[$forms.products.2] }}</td>
							<td class="subTotal">{{ $subtotal[2] }}</td>
							<td>{{ $forms.biko[2] }}</td>
						</tr>

						<tr>
							<td>3</td>
							<td class="prodName">{{ $products[$forms.products.3] }}</td>
							<td>{{ $arr_denpyo[$forms.denpyo.3] }}</td>
							<td>{{ $forms.amount[3] }}</td>
							<td>{{ $units[$forms.products.3] }}</td>
							<td class="subTotal">{{ $subtotal[3] }}</td>
							<td>{{ $forms.biko[3] }}</td>
						</tr>

						<tr>
							<td>4</td>
							<td class="prodName">{{ $products[$forms.products.4] }}</td>
							<td>{{ $arr_denpyo[$forms.denpyo.4] }}</td>
							<td>{{ $forms.amount[4] }}</td>
							<td>{{ $units[$forms.products.4] }}</td>
							<td class="subTotal">{{ $subtotal[4] }}</td>
							<td>{{ $forms.biko[4] }}</td>
						</tr>

						<tr>
							<td>5</td>
							<td class="prodName">{{ $products[$forms.products.5] }}</td>
							<td>{{ $arr_denpyo[$forms.denpyo.5] }}</td>
							<td>{{ $forms.amount[5] }}</td>
							<td>{{ $units[$forms.products.5] }}</td>
							<td class="subTotal">{{ $subtotal[5] }}</td>
							<td>{{ $forms.biko[5] }}</td>
						</tr>

						<tr>
							<td>6</td>
							<td class="prodName">{{ $products[$forms.products.6] }}</td>
							<td>{{ $arr_denpyo[$forms.denpyo.6] }}</td>
							<td>{{ $forms.amount[6] }}</td>
							<td>{{ $units[$forms.products.6] }}</td>
							<td class="subTotal">{{ $subtotal[6] }}</td>
							<td>{{ $forms.biko[6] }}</td>
						</tr>

						<tr>
							<td>7</td>
							<td class="prodName">{{ $products[$forms.products.7] }}</td>
							<td>{{ $arr_denpyo[$forms.denpyo.7] }}</td>
							<td>{{ $forms.amount[7] }}</td>
							<td>{{ $units[$forms.products.7] }}</td>
							<td class="subTotal">{{ $subtotal[7] }}</td>
							<td>{{ $forms.biko[7] }}</td>
						</tr>

						<tr>
							<td>8</td>
							<td class="prodName">{{ $products[$forms.products.8] }}</td>
							<td>{{ $arr_denpyo[$forms.denpyo.8] }}</td>
							<td>{{ $forms.amount[8] }}</td>
							<td>{{ $units[$forms.products.8] }}</td>
							<td class="subTotal">{{ $subtotal[8] }}</td>
							<td>{{ $forms.biko[8] }}</td>
						</tr>

						<tr>
							<td>9</td>
							<td class="prodName">{{ $products[$forms.products.9] }}</td>
							<td>{{ $arr_denpyo[$forms.denpyo.9] }}</td>
							<td>{{ $forms.amount[9] }}</td>
							<td>{{ $units[$forms.products.9] }}</td>
							<td class="subTotal">{{ $subtotal[9] }}</td>
							<td>{{ $forms.biko[9] }}</td>
						</tr>

						<tr>
							<td>10</td>
							<td class="prodName">{{ $products[$forms.products.10] }}</td>
							<td>{{ $arr_denpyo[$forms.denpyo.10] }}</td>
							<td>{{ $forms.amount[10] }}</td>
							<td>{{ $units[$forms.products.10] }}</td>
							<td class="subTotal">{{ $subtotal[10] }}</td>
							<td>{{ $forms.biko[10] }}</td>
						</tr>
{{ /if }}
					</tbody>
				</table>
				{{ $err.detail }}


				<table class="formTable">

					<tbody>
						<tr>
							<th>郵便番号</th>
							<td>
								<input type="text" name="zipcode" id="text_short" class="text" value="{{ $forms.zipcode }}" />
							</td>
						</tr>

						<tr>
							<th>住所</th>
							<td>
								<input type="text" name="address" id="text_information" class="text" value="{{ $forms.address }}" />
							</td>
						</tr>

						<tr>
							<th>電話番号</th>
							<td>
								<input type="text" name="tel" id="text_short" class="text" value="{{ $forms.tel }}" />
							</td>
						</tr>

						<tr>
							<th>会社名</th>
							<td>
								<input type="text" name="company" id="text_information" class="text" value="{{ $forms.company }}" />
							</td>
						</tr>

						<tr>
							<th>部署</th>
							<td>
								<input type="text" name="division" id="text_information" class="text" value="{{ $forms.division }}" />
							</td>
						</tr>

						<tr>
							<th>氏名</th>
							<td>
								<input type="text" name="cust_name" id="text_information" class="text" value="{{ $forms.cust_name }}" />
							</td>
						</tr>

						<tr>
							<th>希望納期</th>
							<td>
								<input type="text" name="limit_date" id="text_information" class="text" value="{{ $forms.limit_date }}" />
							</td>
						</tr>

						<tr>
							<th>午前中指定</th>
							<td>
{{ html_radios name=specify options=$specify selected=$forms.specify separator='&nbsp;' }}
							</td>
						</tr>

						<tr>
							<th>備考</th>
							<td>
								<textarea name="memo" cols="80">{{ $forms.memo }}</textarea>
							</td>
						</tr>
					</tbody>
				</table>

{{ if $forms.id != '' }}
				<table class="formTable">

					<tbody>
						<tr>
							<th>フォロー結果</th>
							<td>
								{{ html_options name=follow_result options=$arr_result selected=$forms.follow_result }}
							</td>
						</tr>
						<tr>
							<th>フォロー1</th>
							<td>
								記入日<input type="text" name="follow_date1" id="text_follow-date1" value="{{ $forms.follow_date1 }}" class="text" /><br />
								<input type="text" name="follow_text1" id="text_information" class="text" value="{{ $forms.follow_text1 }}" />
							</td>
						</tr>
						<tr>
							<th>フォロー2</th>
							<td>
								記入日<input type="text" name="follow_date2" id="text_follow-date2" value="{{ $forms.follow_date2 }}" class="text" /><br />
								<input type="text" name="follow_text2" id="text_information" class="text" value="{{ $forms.follow_text2 }}" />
							</td>
						</tr>
					</tbody>
				</table>
{{ /if }}


				<p class="button">
{{ if $forms.id == '' }}
					<button type="button" id="btn_regist" class="submit"><span>登録</span></button>
{{ else }}
					<button type="button" id="btn_delete" class="submit"><span>削除</span></button>
					<button type="button" id="btn_regist" class="submit"><span>更新</span></button>
{{ /if }}
				</p>
				<input type="hidden" name="id" value="{{ $forms.id }}" />
				<input type="hidden" name="mode" value="input" />
			</form>
{{ /if }}

{{ if $phase == 'complete' }}
			<ul>
{{ if $forms.mode != 'delete' }}
				<li>&gt;&gt; <a href="javascript:open_preview();">印刷画面を表示</a></li>
{{ /if }}
				<li>&gt;&gt; <a href="ship_form.php">続けて登録する</a></li>
				<li>&gt;&gt; <a href="ship_index.php">一覧へ戻る</a></li>
			</ul>
{{ /if }}
		</div></div>
		<address>Copyright (C) SHIFT Inc. / All rightes reserved</address>
	</body>

</html>